import com.sun.xml.internal.ws.addressing.WsaActionUtil;

import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-04-16
 * Time: 14:25
 */
public class TestDemo {


    public static void main(String[] args) {
        String str = "        Hello,world             ";
        System.out.println(str.trim());
    }


    public static void main23(String[] args) {
        String str ="198.162.358.263";
        //将字符串str以字符.来分割为4组。limit如果超出范围就按最多的组划分
        //特殊字符.要用\\转义 两个\代表一个\
        String[] strings =str.split("\\.",4);
        for(String s1:strings) {
            System.out.println(s1);
        }
    }


    public static void main22(String[] args) {
        String str ="ILoveJava";
        String s;

        String s1 = str.substring(1,5);
       // System.out.println(s);//截取到下标1位置，从下标1位置开始截取
        System.out.println(s1);//截取[1,5)下标，左闭右开
    }


    public static void main21(String[] args) {
         String s = "name=lisi#score=100.0";
        //先按照#划分为两组一组是name = lisi，一组是score = 100.0
         String[] result = s.split("#");
         for(int i =0;i<result.length;++i) {
             //在按照=划分为两组 一组为name = lisi 一组score= 100.0
             String[] temp = result[i].split("=");
             System.out.println(temp[0]+ "="+ temp[1]);
         }
    }

    public static void main20(String[] args) {
           String s = "Hello My World";
           //按照空格进行划分为两组
           String[] strings = s.split(" ",2);
           for(String s1:strings) {
               System.out.println(s1);
           }
    }
    public static void main17(String[] args) {
          //字符串替换
        String str ="Hello,houJiBoFa";
        String s = str.replace("houJiBoFa","CsDn");//将houjibofa替换成CsDn;
        System.out.println(s);
        String str1 = "Hello,China";
        System.out.println(str1.replaceAll("l","&"));//将所有的l替换成&
        System.out.println(str1.replaceFirst("l","#"));//将所有的l替换成#
    }

    public static void main18(String[] args) {
       int[] array = {1,2,3,4,4,5,6,7,8,9};
        System.out.println(Arrays.toString(array));
        char[] chars = {'a','b','c','d','e'};
        System.out.println(Arrays.toString(chars));

    }

    public static void main16(String[] args) {
        //小写转大写  只有小写字母转化成大写字母，大写字母不变，其他符号不变
        String s = "HELLO,WORLD";
        System.out.println(s.toLowerCase());
        //大写转小写  只有大写字母转化成小写字母，小写字母不变，其他符号不变
        String s1 = "hello,world";
        System.out.println(s1.toUpperCase());
    }


    public static void main15(String[] args) {
         //字符串转整数->Integer.valueOf(String s)
        String str = "1314";
        int x = Integer.valueOf(str);
        System.out.println(x);
        int tmp =x+100;
        System.out.println(tmp);
        //字符串转整数->Integer.paseInt
        int tmp1 =Integer.parseInt(str);
        System.out.println(tmp1);
        int tmp2 = tmp1+100;
        System.out.println(tmp2);
    }

    public static void main14(String[] args) {
        String s ="hel lo";
        System.out.println(s.endsWith("o"));
        System.out.println(s.startsWith("h"));
        System.out.println(s.contains("ll"));
        System.out.println(s.isEmpty());
    }

    public static void main13(String[] args) {
          //字符串替换
        String str ="ILoveYou";
        String s = str.replace("I","You");
        //String s1 = str.replaceAll()
        System.out.println(s);
    }

    public static void main12(String[] args) {
        //trim去掉字符串左右的所有空格
        String s = "         ILoveYou                 ";
        String str = s.trim();
        System.out.println(str);
    }

    public static void main11(String[] args) {
        //字符串截取
        //采取先闭后开区间
        String str ="abcdefghijklmn";
        System.out.println(str.substring(5));
        String s = str.substring(0,4);
        System.out.println(s);
    }

    public static void main10(String[] args) {
        //字符串多次拆分
        String str = "name=zhangsan&age=18" ;
        String[] result = str.split("&");

        for(int i =0;i<result.length;++i) {
            String[] temp = result[i].split("=");
            System.out.println(temp[0]+" = "+temp[1]);
        }
//        String str = "name=zhangsan&age=18" ;
//        String[] result = str.split("&") ;
//        for(int i = 0; i < result.length; i++) {
//            String[] temp = result[i].split("=") ;
//            System.out.println(temp[0]+" = "+temp[1]);
//        }
    }

    public static void main9(String[] args) {
        String str = "t*t*yu*i";
        String[] strings = str.split("\\*",3);
        for(String s:strings) {
            System.out.println(s);
        }
    }


    public static void main7(String[] args) {
        String str = "t\\t\\yu\\i";
        String[] strings = str.split("\\\\",3);
        for(String s:strings) {
            System.out.println(s);
        }
    }


    public static void main6(String[] args) {
        //字符串拆分
        String str ="abc def tyu";
        String[] strings = str.split(" ",2);
        for (String s:strings) {
            System.out.println(s);
        }
    }


    public static void main5(String[] args) {
        //字符串替换
        String str = "ILoveYou";
        String s = str.replace("You","me");
        System.out.println(s);
    }


    public static void main4(String[] args) {
        //格式化字符串
        String s = String.format("%d<->%d<->%d",2022,04,16);
        System.out.println(s);
    }

    public static void main3(String[] args) {
        //字符串转数组
        String s = "1234567890";
        char[] ch = s.toCharArray();
        System.out.println(Arrays.toString(ch));
        //将字符串格式化

    }
    public static void main2(String[] args) {
        //大小写转换
        //大写->小写
        String str ="HELLO";
        String str1 = str.toLowerCase();
        System.out.println(str1);
        //小写->大写
        String str2 = "ertyuio";
        String str3 = str2.toUpperCase();
        System.out.println(str3);
    }

    public static void main1(String[] args) {
//         //数字转化成字符串
//        int a =10;
//        String str = String.valueOf(10);
//        str+="1";
//        System.out.println(str);
        //字符串转化成数字
//        int a = Integer.valueOf("1000");
//        System.out.println(a);
//        System.out.println(Integer.valueOf("109"));


    }

}
